﻿using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using System;
namespace ugui.demo1
{
    //PointerEventData scrollDelta 还是不太理解这么用
    public class scrollDelta : MonoBehaviour, IDragHandler
    {
        public ScrollRect _scrollView;
        public Image m_DraggingIcon;
        public Vector2 onBeginDragPosition;
        public void Start()
        {
            onBeginDragPosition = transform.localPosition;
        }
        public void OnDrag(PointerEventData data)
        {
            if (m_DraggingIcon != null)
            {
                SetDraggedPosition(data);
            }
            else
            {

                Vector2 tempPosition = data.position;
                if ((tempPosition.x > onBeginDragPosition.x + 2) &&
                Mathf.Abs(tempPosition.x - onBeginDragPosition.x) > Mathf.Abs(tempPosition.y - onBeginDragPosition.y) &&
                data.pointerCurrentRaycast.gameObject == data.pointerPressRaycast.gameObject)
                {

                    creatm_DraggingIcon(data);
                }
                else if (Mathf.Abs(tempPosition.y - onBeginDragPosition.y) > Mathf.Abs(tempPosition.x - onBeginDragPosition.x))
                {
                    data.scrollDelta = new Vector2(0, -data.delta.y * 2);
                }
            }
            data.IsScrolling();

        }
        public void SetDraggedPosition(PointerEventData data)
        {

        }

        public void creatm_DraggingIcon(PointerEventData data)
        {

        }
    }
}
